package com.video.web.controller.video;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.video.common.annotation.Log;
import com.video.common.core.controller.BaseController;
import com.video.common.core.domain.AjaxResult;
import com.video.common.enums.BusinessType;
import com.video.video.domain.DBanner;
import com.video.video.service.IDBannerService;
import com.video.common.utils.poi.ExcelUtil;
import com.video.common.core.page.TableDataInfo;

/**
 * 轮播广告Controller
 *
 * @author ruoyi
 * @date 2022-09-29
 */
@RestController
@RequestMapping("/video/banner")
public class DBannerController extends BaseController
{
    @Autowired
    private IDBannerService dBannerService;

    /**
     * 查询轮播广告列表
     */
    @PreAuthorize("@ss.hasPermi('video:banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(DBanner dBanner)
    {
        startPage();
        List<DBanner> list = dBannerService.selectDBannerList(dBanner);
        return getDataTable(list);
    }

    /**
     * 导出轮播广告列表
     */
    @PreAuthorize("@ss.hasPermi('video:banner:export')")
    @Log(title = "轮播广告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DBanner dBanner)
    {
        List<DBanner> list = dBannerService.selectDBannerList(dBanner);
        ExcelUtil<DBanner> util = new ExcelUtil<DBanner>(DBanner.class);
        util.exportExcel(response, list, "轮播广告数据");
    }

    /**
     * 获取轮播广告详细信息
     */
    @PreAuthorize("@ss.hasPermi('video:banner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(dBannerService.selectDBannerById(id));
    }

    /**
     * 新增轮播广告
     */
    @PreAuthorize("@ss.hasPermi('video:banner:add')")
    @Log(title = "轮播广告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DBanner dBanner)
    {
        return toAjax(dBannerService.insertDBanner(dBanner));
    }

    /**
     * 修改轮播广告
     */
    @PreAuthorize("@ss.hasPermi('video:banner:edit')")
    @Log(title = "轮播广告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DBanner dBanner)
    {
        return toAjax(dBannerService.updateDBanner(dBanner));
    }

    /**
     * 删除轮播广告
     */
    @PreAuthorize("@ss.hasPermi('video:banner:remove')")
    @Log(title = "轮播广告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(dBannerService.deleteDBannerByIds(ids));
    }
}
